using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

using System.Web.Security;

namespace OpenProject.DataObjects
{
    /// <summary>
    /// Controller class for RevisionType
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class RevisionTypeController
    {
        // Preload our schema..
        static RevisionType thisSchemaLoad = new RevisionType();
        private static string _userName = string.Empty;
        protected static string UserName
        {
            get
            {
				if (_userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						_userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						_userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return _userName;
            }

        }

        private static int _userId = 0;
        protected static int UserId
        {
            get
            {
				if (_userId == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
    				    MembershipUser user = Membership.GetUser();
                        if (user != null)
                            _userId = (int)user.ProviderUserKey;
					}

				}

				return _userId;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static RevisionTypeCollection FetchAll()
        {
            RevisionTypeCollection coll = new RevisionTypeCollection();
            Query qry = new Query(RevisionType.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static RevisionTypeCollection FetchByID(object RevisionTypeId)
        {
            RevisionTypeCollection coll = new RevisionTypeCollection().Where("RevisionTypeId", RevisionTypeId).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public static RevisionTypeCollection FetchByQuery(Query qry)
        {
            RevisionTypeCollection coll = new RevisionTypeCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(object RevisionTypeId)
        {
            return (RevisionType.Delete(RevisionTypeId) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public static bool Destroy(object RevisionTypeId)
        {
            return (RevisionType.Destroy(RevisionTypeId) == 1);
        }

        
        
        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(int RevisionTypeId)
        {
            Query qry = new Query(RevisionType.Schema);
            qry.QueryType = QueryType.Delete;
            qry.AddWhere("RevisionTypeId", RevisionTypeId);
            qry.Execute();
            return (true);
        }
        
       
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public static int Insert(int RevisionTypeId,string Title)
	    {
		    RevisionType item = new RevisionType();
		    
            item.RevisionTypeId = RevisionTypeId;
            
            item.Title = Title;
            
	    
		    item.Save(UserId);
		    return item.RevisionTypeId;
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public static void Update(int RevisionTypeId,string Title)
	    {
		    RevisionType item = new RevisionType();
		    
				item.RevisionTypeId = RevisionTypeId;
				
				item.Title = Title;
				
		    item.MarkOld();
		    item.Save(UserId);
	    }

    }

}

